/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-9-13
 * Time: 下午6:41
 * To change this template use File | Settings | File Templates.
 */
String.prototype.stringFormat = function () {
    var params = arguments;
    if (params.length == 0) {
        return this;
    }

    if ($.isArray(params[0])) {
        params = params[0];
    }

    for (var s = this, i = 0; i < params.length; i++) {
        s = s.replace(new RegExp("\\{" + i + "\\}", "g"), params[i]);
    }
    return s;
};

var XSPS_URL = "/wlgl/xsps/xsps_content_print?xsdId={0}&xspsId={1}";
var XY_URL = "/jhgl/xygl/xygl_detail?xyId={0}";
var WZJH_URL = "/jhgl/wzjhgl/wzjhgl_detail?id={0}";
var ZJJH_URL = "/jhgl/zjjhgl/zjjhgl_detail?id={0}&type={1}";
var JKD_URL = "/jhgl/jkd/jkd_detail?jkdId={0}";
var CGHT_URL = "/htgl/cghtgl/cghtgl_detail?cghtId={0}";
var XSHT_URL = "/htgl/xshtgl/xshtgl_detail?xshtId={0}";
//---hl---
var ZJBCHT_URL = "/htgl/zjbchtgl/zjbcht_detail?xshtId={0}";
//---hl---
var BGHT_URL = "/htgl/bghtgl/bghtgl_detail?bghtId={0}";
var CGD_URL = "/cggl/cgdgl/cgdgl_detail?cgd.id={0}";
var XSD_URL = "/xsgl/xsdgl/xsdgl_detail?xsdId={0}";
var XPD_URL = "/xsgl/xsdgl/xsdexamine_detail?xsdId={0}";
var CGDTZ_URL = "/cggl/cgdtz/cgdtz_detail?cgd.id={0}";
var XSDTZ_URL = "/xsgl/xsdtz/xsdtz_detail?xsdId={0}";
var CGJSD_URL = "/jsgl/cgjsd/cgjsd_detail?cgjsdId={0}";
var XSJSD_URL = "/jsgl/xsjsd/xsjsd_detail?xsjsdId={0}";
var BGCGD_URL = "/cggl/bgcgdgl/bgcgdgl_detail?cgd.id={0}";
var NBLL_URL = "/kcgl/nbll/nbll_detail?lldId={0}";
var LJWH_URL = "/organ/ljwh/ljwh_detail?ljId={0}";
var LJWHKCLS_URL = "/organ/ljwh_kcls/ljwh_kcls_detail?ljId={0}";
var GYS_URL = "/organ/gys/gys_detail?ljLsId={0}";
var RKSH_URL = "/kcgl/rksh/rksh_detail?rksh.id={0}";
var CKSH_URL = "/kcgl/cksh/cksh_detail?xsdId={0}";
var SLSH_URL = "/kcgl/slsh/slsh_detail?xsdId={0}";
var SSKC_URL = "/kcgl/sskc/sskc_detail?khId={0}";
var KCGD_URL = "/kcgl/kcgd/kcgd_detail?khId={0}";
var WLJS_URL = "/jsgl/wljsd/wljsd_detail?wljsdId={0}";
var ZKSH_URL = "/kcgl/zksq/zksq_detail?zkdId={0}";
var NBXSD_URL = "/xsgl/nbxsd/nbxsd_detail?xsdId={0}";
var NBCGD_URL = "/cggl/nbcgd/nbcgd_detail?cgd.id={0}";
var KCPD_URL = "/kcgl/kcpd/kcpd_detail?kcpdId={0}";
var LRCS_URL = "/tjbb/yjykhhz/lrcs_detail?year={0}&month={1}&ll={2}";
var JGD_URL = "/jggl/jgdgl/jgd_detail?jgdId={0}";
var SKDR_URL = "/cwgl/skdr/skdr_detail?skshId={0}";
var XSDGK_URL = "/xsgl/xsdgl/xsdgk_detail?xsdId={0}";
var XSDPK_URL = "/xsgl/xsdgl/xsdpk_detail?xsdId={0}";
var GSPZ_URL = "/base/gspz/gspz_detail?gspzId={0}";



//公式配置-详细
function gspzCell(val, row) {
    return formatterCell1(val, "GSPZ_URL", row.id);
}
//采购合同-详细
function skdrCell(val, row) {
    return formatterCell(val, "SKDR_URL", row.id);
}
//销售配送单-详细
function xspsCell(val, row) {
    return formatterCell(val, "XSPS_URL", [row.id, row.psd_id || -1].join(","));
}

//协议-详细
function xyCell(val, row) {
    return formatterCell(val, "XY_URL", row.id);
}

//物资计划-详细
function wzjhCell(val, row) {
    return formatterCell(val, "WZJH_URL", row.id);
}

//资金计划-详细
function zjjhCell(val, row) {
    return formatterCell(val, "ZJJH_URL", [row.id, row.TYPE].join(","));
}

//借款单-详细
function jkdCell(val, row) {
    return formatterCell(val, "JKD_URL", row.id);
}

//采购合同-详细
function cghtCell(val, row) {
    return formatterCell(val, "CGHT_URL", row.id);
}

//销售合同-详细
function xshtCell(val, row) {
    return formatterCell(val, "XSHT_URL", row.id);
}


//---hl---
function zjbchtCell(val, row) {
    //alert(row.id);
    return formatterCell(val, "ZJBCHT_URL", row.id);
}
//---hl---


//保供合同-详细
function bghtCell(val, row) {
    return formatterCell(val, "BGHT_URL", row.id);
}

//送货单-详细
function cgdCell(val, row) {
    return formatterCell(val, "CGD_URL", row.id);
}

//销售单-详细
function xsdCell(val, row) {
    return formatterCell(val, "XSD_URL", row.XSDID || row.id);
}

//销售出库管理-详细
function xsdCkGlCell(val, row) {
    return formatterCell(val, "XSDGK_URL", row.XSDID || row.id);
}

//销售配款管理-详细
function xsdPKGlCell(val, row) {
    return formatterCell(val, "XSDPK_URL", row.XSDID || row.id);
}

//新凭单-详细
function xpdCell(val, row) {
    return formatterCell(val, "XPD_URL", row.id);
}

//送货单冲销-详细
function cgdtzCell(val, row) {
    return formatterCell(val, "CGDTZ_URL", row.id);
}

//销售单冲销-详细
function xsdtzCell(val, row) {
    return formatterCell(val, "XSD_URL", row.id);
}

//采购结算单-详细
function cgjsdCell(val, row) {
    return formatterCell(val, "CGJSD_URL", row.id);
}

//采购单detail中采购结算单的链接
function cgjsdDetailCell(val, row) {
    return formatterCell(val, "CGJSD_URL", row.jsdId);
}

//销售结算单-详细
function xsjsdCell(val, row) {
    return formatterCell(val, "XSJSD_URL", row.id);
}

//销售单关联结算单跳转-详细
function xsdToXsjsdCell(val, row) {
    return formatterCell(val, "XSJSD_URL", row["jsd.id"]);
}

//保供采购单-详细
function bgcgdCell(val, row) {
    return formatterCell(val, "BGCGD_URL", row.id);
}

//内部领料-详细
function nbllCell(val, row) {
    return formatterCell(val, "NBLL_URL", row.id);
}

//路经维护-详细
function ljwhCell(val, row) {
    return formatterCell(val, "LJWH_URL", row.id);
}

//零售路径维护-详细
function ljwhKclsCell(val, row) {
    return formatterCell(val, "LJWHKCLS_URL", row.id);
}

//添加供应商-详细
function gysCell(val, row) {
    return formatterCell(val, "GYS_URL", row.id);
}

//入库审核-详细
function rkshCell(val, row) {
    return formatterCell(val, "RKSH_URL", row.id);
}

//出库审核-详细
function ckshCell(val, row) {
    return formatterCell(val, "CKSH_URL", row.id);
}

//数量审核-详细
function slshCell(val, row) {
    return formatterCell(val, "SLSH_URL", row.id);
}

//实时库存-详细
function sskcYCell(val, row) {
    return formatterCell(val, "SSKC_URL", row.id);
}

//物流结算-详细
function wljsCell(val, row) {
    return formatterCell(val, "WLJS_URL", row.id);
}

//转库申请-详细
function zkshCell(val, row) {
    return formatterCell(val, "ZKSH_URL", row.id);
}

//内部销售单-详细
function nbxsdCell(val, row) {
    return formatterCell(val, "NBXSD_URL", row.id);
}

//内部采购单-详细
function nbcgdCell(val, row) {
    return formatterCell(val, "NBCGD_URL", row.id);
}

//盘点明细-详细
function pdmxCell(val, row) {
    return formatterCell(val, "KCPD_URL", row.id);
}

//关联费用-详细
function glfyCell(val, row) {
    if (row['cgd.id'])
        return formatterCell(val, "CGD_URL", row['cgd.id']);
    else if (row['xsd.id'])
        return formatterCell(val, "XSD_URL", row['xsd.id']);
    else
        return val;
}

//加工单-详细
function jgdCell(val, row) {
    return formatterCell(val, "JGD_URL", row.id);
}

//利润参数弹框
function lsrcDetal(val, row) {
    return formatterCellForLsrc(val, "LRCS_URL", [row['YEAR'], row['MONTH'], row['LL']].join(","));
}

function formatterCell(val, url, params) {
    if (!val) {
        return;
    }
    var a = "javascript:detail('{0}','{1}');".stringFormat(url, params);
    return '<a href="' + a + '" style="color: red">' + val + '</a>';
}

function detail(url, params) {
    $.window({
        title:"详细",
        iconCls:'icon-tip',
        url:$.webPath() + eval(url).stringFormat(params.split(",")),
        width:1200,
        height:500
    });
}

function formatterCellForLsrc(val, url, params) {
    if (!val) {
        return;
    }
    var a = "javascript:detailForLcrs('{0}','{1}');".stringFormat(url, params);
    return '<a href="' + a + '" style="color: blue">' + '修改' + '</a>';
}

function detailForLcrs(url, params) {
    var tit = "修改利率参数";
    var win = $.window({
        title:tit,
        width:420,
        height:400,
        url:$.webPath() + eval(url).stringFormat(params.split(",")),
        modal:true,
        buttons:[
            {
                text:'保存',
                handler:function () {
                    $(win).mask();
                    $('#form_lrcs_detial').form('submit', {
                        url:$.webPath() + "/tjbb/yjykhhz/lrcs_update",
                        onSubmit:function () {
                            var isValid = $(this).form('validate');
                            if (!isValid) {
                                $(win).mask('hide');
                                return false;
                            }
                            return isValid;
                        },
                        success:function (data) {
                            $(win).mask('hide');
                            var json = $.parseJSON(data);
                            if (json.statusCode == 200) {
                                $(win).window('close');
                                $('#lrcs_grid').datagrid('reload');
                                $.messager.show({
                                    title:'提示',
                                    msg:json.message,
                                    timeout:3000,
                                    showType:'slide'
                                });
                            } else
                                $.messager.alert('提示', json.message, 'error');
                        }
                    });
                }
            }
        ]
    });

}

function formatterCell1(val, url, params) {
    if (!val) {
        return;
    }
    var a = "javascript:detail1('{0}','{1}');".stringFormat(url, params);
    return '<a href="' + a + '" style="color: red">' + val + '</a>';
}

function detail1(url, params) {
    $.window({
        title:"详细",
        iconCls:'icon-tip',
        url:$.webPath() + eval(url).stringFormat(params.split(",")),
        width:800,
        height:400
    });
}